package com.hydl.power.controller;

import com.github.pagehelper.PageInfo;
import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.pojo.Identical;
import com.hydl.power.pojo.MaintenanceReport;
import com.hydl.power.pojo.OpsReport;
import com.hydl.power.pojo.WorkOrder;
import com.hydl.power.service.CarService;
import com.hydl.power.service.MaintenanceReportService;
import com.hydl.power.service.WorkOrderService;
import com.hydl.power.utils.EasyPoiUtil;
import com.hydl.power.utils.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "MaintenanceReportController", tags = "运维报告")
@RestController
@RequestMapping("/MaintenanceReport")
@CrossOrigin
public class MaintenanceReportController {

    @Autowired
    private MaintenanceReportService maintenanceReportService;
    @Autowired
    private WorkOrderService workOrderService;

    //@LogAnnotation(module = "运维报告",description = "运维报告One")
    @PostMapping("/queryOpsReport")
    @ApiOperation("运维报告One")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数",required = false,  dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "cityId", value = "城市id",required = false,  dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "roomId", value = "配电房id",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "token", value = "token",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "dataType", value = "dataType",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "time", value = "time",required = false, dataType = "String"),
    })
    public Resp queryOpsReport(Integer pageNum, Integer pageSize, String cityId, String projectId, String roomId, String dataType, String time, String token) {
        return Resp.success(maintenanceReportService.queryOpsReport(pageNum,pageSize,cityId,projectId,roomId,dataType,time,token));
    }

    //  @LogAnnotation(module = "运维报告导出",description = "运维报告导出")
    @GetMapping("/queryOpsReportExport")
    @ApiOperation("运维报告导出")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数",required = false,  dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "cityId", value = "城市id",required = false,  dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "roomId", value = "配电房id",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "token", value = "token",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "dataType", value = "dataType",required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "time", value = "time",required = false, dataType = "String"),
    })
    public void queryOpsReportExport(Integer pageNum, Integer pageSize, String cityId, String projectId, String roomId, String dataType, String time, String token,
                                     HttpServletResponse response)throws Exception{
        PageInfo<MaintenanceReport> pageInfo = maintenanceReportService.queryOpsReport(pageNum,pageSize,cityId,projectId,roomId,dataType,time,token);
        List<MaintenanceReport> arr = pageInfo.getList();
        EasyPoiUtil.exportExcel(EasyPoiUtil.getWorkbook("运维报告", "运维报告", MaintenanceReport.class, arr), "运维报告", response);
    }



    //  @LogAnnotation(module = "运维报告List",description = "根据设备id查询报警信息")
    @PostMapping("/queryByDeviceId")
    @ApiOperation("设备告警信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",required = false, dataType = "String"),
    })
    public Resp queryOpsReport(String deviceId) {
        return Resp.success(workOrderService.queryByDeviceId(deviceId));
    }

    //   @LogAnnotation(module = "运维报告List导出Excel",description = "运维报告List导出Excel")
    @GetMapping("/deviceIdExport")
    @ApiOperation("运维报告List导出Excel")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",required = false, dataType = "String"),
    })
    public void queryOpsReportExcel(String deviceId,HttpServletResponse response) throws Exception{
         List<OpsReport> list = workOrderService.queryByDeviceId(deviceId);
        EasyPoiUtil.exportExcel(EasyPoiUtil.getWorkbook("设备故障信息", "设备故障信息", OpsReport.class, list), "设备故障信息", response);
    }
}
